package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.throwingPot.ThrowingPotMgr;

import java.util.List;

public class TrystItemRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        List<ActivityInfo> activityInfoList = NormalActivityMgr.getTrystActivityInfoList();
        if (activityInfoList != null) {
            for (ActivityInfo activityInfo : activityInfoList) {
                int itemId = Integer.parseInt(activityInfo.getParam4().split(";")[0]);
                long recycleTime = activityInfo.getEndShowTime() * 1000L + 10 * 60 * 1000;
                ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, recycleTime);
                if (activityInfo.getChildType() == 6) {
                    ActivityItemRecycleMgr.addRecycleItemData(eItemId.FireCracker.getValue(), activityType, recycleTime);
                }
                if (activityInfo.getParam4().split(";").length >= 3) {  //送财道具
                    ActivityItemRecycleMgr.addRecycleItemData(Integer.parseInt(activityInfo.getParam4().split(";")[2]), activityType, recycleTime);
                }
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.TrystActivity.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int itemId = data.getItemId();
        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        if (userBagItem != null && userBagItem.getNum() > 0) {
            removeItem(userBagItem);
        }
    }

}
